<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <!-- import Vue.js -->
    <script src="./vue.min.js"></script>
    <!-- import stylesheet -->
    <link rel="stylesheet" href="./iview.css">
    <link rel="stylesheet" href="./reset.css">
    <!-- import iView -->
    <script src="./iview.min.js"></script>
    <script src="./axios.min.js"></script>
</head>

<body>
    <div id="app">
        <div v-if="showimg">
            <img v-bind:src="imgsrc" style="width:100%;height:100%;" alt="">
        </div>
        <div v-else>
            <div class="config">
                <p>实名制认证</p>
            </div>

            <div class="con" v-show="show">
                <span>{{higher_name}}邀请你加入他/她的团队</span>
                <span>当前等级为:{{levelName}}</span>

                <div class="info">
                    <div class="fl">真实姓名</div>
                    <input type="text" class="fr" v-model="name">
                </div>
                <div class="info">
                    <div class="fl">身份证号</div>
                    <input type="text" class="fr" v-model="c_num">
                </div>
                <div class="info">
                    <div class="fl">手机号</div>
                    <input type="number" class="fr" v-model="p_num">
                </div>
                <div class="info">
                    <div class="fl">手机验证码</div>
                    <input type="number" v-model="s_num" style="width:15%;padding-right:0px">
                    <button class="yzm" @click="code()" id="yzm">获取验证码</button>

                </div>
                <div class="info">
                    <div class="fl">登录密码</div>
                    <input type="password" class="fr" v-model="pwd">
                </div>
                <div class="info">
                    <div class="fl">请再次输入登录密码</div>
                    <input type="password" class="fr" v-model="repassword">
                </div>
                <div class="info">
                    <div class="fl">性别</div>
                    <select name="" id="" style="float:right" v-model="sex">
                        <option value="1">男</option>
                        <option value="0">女</option>
                    </select>
                </div>
                <div class="info">
                    <div class="fl">年龄</div>
                    <input type="number" class="fr" v-model="age">
                </div>
                <div class="info">
                    <div class="fl">地址</div>
                    <input type="text" class="fr" v-model="address">
                </div>
                <div class="info">
                    <div class="fl">开户银行</div>
                    <input type="text" class="fr" v-model="bank">
                </div>
                <div class="info">
                    <div class="fl">银行卡号</div>
                    <input type="text" class="fr" v-model="b_num">
                </div>
                <div class="info">
                    <div class="fl">支付宝账号</div>
                    <input type="text" class="fr" v-model="alipay">
                </div>
                <div class="info">
                    <div class="fl">微信账号</div>
                    <input type="text" class="fr" v-model="wechat">
                </div>
                <div class="photo">
                    <div class="text">身份证正面</div>
                    <input type="file" class="file" @change="change1()" id="file1" name="file">
                    <div class="addfile">
                        <img src="./add.png" alt="" class="img" id="img1">

                    </div>
                </div>
                <div class="photo">
                    <div class="text">身份证反面</div>
                    <input type="file" class="file" @change="change2()" id="file2" name="file">
                    <div class="addfile">
                        <img src="./add.png" alt="" class="img" id="img2">

                    </div>
                </div>

                <div class="btn" @click="ok()">
                    <button>提交审核</button>
                </div>
            </div>
            <div class="con1" v-show="!show">
                <h1>当前分享页面链接已失效</h1>
                <h1>请重新向上级获取</h1>

            </div>
        </div>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                imgsrc: "",
                showimg: true,
                siteUrl: "http://m.mirrorcare.cn/api",
                name: "",
                p_num: "",
                c_num: "",
                age: "",
                bank: "",
                b_num: "",
                alipay: "",
                wechat: "",
                sex: 1,
                info: "",
                state: 0,
                uid: "",
                certificate_url: "",
                certificate_back_url: "",
                encode: "",
                level: "",
                levelName: "",
                s_num: "",
                pwd: "",
                repassword: "",
                obj: "",
                show: true,
                address: "",
                higher_name: "",
                higher_up: ""
            },
            beforeCreate: function() {
                document.getElementsByTagName("body")[0].style.background = "#fff";
            },
            methods: {
                ok: function() {
                    var $__5 = this;
                    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
                    if (this.name == "") {
                        this.$Message.warning("真实姓名不能为空");
                    } else if (this.c_num == "") {
                        this.$Message.warning("身份证号不能为空");
                    } else if (this.p_num == "") {
                        this.$Message.warning("手机号不能为空");
                    } else if (!myreg.test(this.p_num)) {
                        this.$Message.error("请填写正确的手机号");
                    } else if (this.s_num == "") {
                        this.$Message.warning("验证码不能为空");
                    } else if (this.pwd == "") {
                        this.$Message.warning("密码不能为空");
                    } else if (this.repassword == "") {
                        this.$Message.warning("再次输入密码不能为空");
                    } else if (this.age == "") {
                        this.$Message.warning("年龄不能为空");
                    } else if (this.address == "") {
                        this.$Message.warning("地址不能为空");
                    } else if (this.bank == "") {
                        this.$Message.warning("开户行不能为空");
                    } else if (this.b_num == "") {
                        this.$Message.warning("银行卡号不能为空");
                    } else if (this.alipay == "") {
                        this.$Message.warning("支付宝账号不能为空");
                    } else if (this.wechat == "") {
                        this.$Message.warning("微信账号不能为空");
                    } else if (document.getElementById("file1").files[0] == undefined) {
                        this.$Message.warning("身份证正面不能为空");
                    } else if (document.getElementById("file2").files[0] == undefined) {
                        this.$Message.warning("身份证反面不能为空");
                    } else {
                        var param = new FormData();
                        param.append("name", this.name);
                        param.append("p_num", this.p_num);
                        param.append("s_num", this.s_num);
                        param.append("password", this.pwd);
                        param.append("repassword", this.repassword);
                        param.append("age", this.age);
                        param.append("address", this.address);
                        param.append("sex", this.sex);
                        param.append("bank", this.bank);
                        param.append("b_num", this.b_num);
                        param.append("c_num", this.c_num);
                        param.append("alipay", this.alipay);
                        param.append("wechat", this.wechat);
                        param.append("encode", this.encode);
                        param.append("file", document.getElementById("file1").files[0]);
                        param.append("file", document.getElementById("file2").files[0]);
                        this.$Spin.show({
                            render: function(h) {
                                return h("div", [h("Icon", {
                                    class: "demo-spin-icon-load",
                                    props: {
                                        type: "load-c",
                                        size: 18
                                    }
                                }), h("div", "Loading")]);
                            }
                        });
                        axios({
                            method: "post",
                            url: (this.siteUrl + "/insertUser"),
                            data: param
                        }).then(function(response) {
                            if (response.data.result == 200) {
                                console.log(response);
                                $__5.$Spin.hide();
                                alert("等待后台审核，审核成功后,进入微信公众号进行登录");
                            } else {
                                $__5.$Spin.hide();
                                alert(response.data.message);
                            }
                        }).catch(function(error) {
                            console.log(error);
                        });
                    }
                },
                change1: function() {
                    var file1 = document.getElementById("file1").files[0];
                    var url = URL.createObjectURL(file1);
                    document.getElementById("img1").src = url;
                    document.getElementById("img1").style.width = "120px";
                    document.getElementById("img1").style.height = "70px";
                    document.getElementById("img1").style.marginTop = "0px";
                },
                change2: function() {
                    var file2 = document.getElementById("file2").files[0];
                    var url = URL.createObjectURL(file2);
                    document.getElementById("img2").src = url;
                    document.getElementById("img2").style.width = "120px";
                    document.getElementById("img2").style.height = "70px";
                    document.getElementById("img2").style.marginTop = "0px";
                },
                code: function() {
                    var $__5 = this;
                    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
                    if (this.p_num == "") {
                        this.$Message.warning("手机号不能为空");
                    } else if (!myreg.test(this.p_num)) {
                        this.$Message.error("请填写正确的手机号");
                    } else {
                        var doLoop = function() {
                            nums--;
                            if (nums > 0) {
                                yzm.innerHTML = nums + "秒后可重新获取";
                            } else {
                                clearInterval(clock);
                                yzm.disabled = false;
                                yzm.style.backgroundColor = "#5aa0c8";
                                yzm.innerHTML = "点击发送验证码";
                                nums = 60;
                            }
                        };
                        var yzm = document.getElementById("yzm");
                        var clock = "";
                        var nums = 60;
                        yzm.disabled = true;
                        yzm.style.backgroundColor = "#ccc";
                        yzm.innerHTML = nums + "秒后可重新获取";
                        clock = setInterval(doLoop, 1000);
                        axios({
                            method: "post",
                            url: (this.siteUrl + "/getSecretNumber"),
                            data: {
                                p_num: this.p_num
                            }
                        }).then(function(response) {
                            console.log(response);
                            if (response.data.result == 200) {
                                console.log(response);
                            } else {
                                $__5.$Message.warning(response.data.message);
                            }
                        }).catch(function(error) {
                            console.log(error);
                        });
                    }
                },
                select: function() {
                    var $__5 = this;
                    console.log(2);
                    axios({
                        method: "post",
                        url: (this.siteUrl + "/getUser"),
                        data: {
                            uid: this.higher_up
                        }
                    }).then(function(response) {
                        console.log(response);
                        if (response.data.result == 200) {
                            var data = response.data.data;
                            $__5.higher_name = data.name;
                            console.log($__5.higher_name);
                        } else {
                            alert("请求失败");
                        }
                    }).catch(function(error) {
                        console.log(error);
                    });
                }
            },
            mounted: function() {
                var $__5 = this;
                this.obj = window.location.search;
                this.level = this.obj.slice(7, 8);
                this.uid = this.obj.slice(19, 30);
                var uid = localStorage.getItem("uid");
                console.log(this.uid + "  " + uid);
                if (uid == this.uid && (this.level == '1' || this.level == '2' || this.level == '3')) {
                    this.showimg = true;
                    this.imgsrc = "./" + this.level + ".png";
                } else {
                    this.showimg = false;
                }
                this.$Message.config({
                    top: 200,
                    duration: 2
                });
                axios({
                    method: "post",
                    url: (this.siteUrl + "/getTime"),
                    data: {
                        url: this.obj
                    }
                }).then(function(response) {
                    if (response.data.result == 200) {
                        $__5.time = response.data.data.time * 1000;
                        var timestamp = new Date().getTime();
                        if (timestamp - $__5.time >= 60*60*1000) {
                            $__5.show = false;
                        } else {
                            alert("此分享链接有效时长为一小时");
                            var obj = window.location.href;
                            if (obj.lastIndexOf("?") != -1) {
                                var index = obj.lastIndexOf("?");
                                obj = obj.substring(index + 1, obj.length);
                                if ($__5.level == "1") {
                                    $__5.levelName = "联合创始人";
                                } else if ($__5.level == "2") {
                                    $__5.levelName = "执行董事";
                                } else if ($__5.level == "3") {
                                    $__5.levelName = "合伙人";
                                } else if ($__5.level == "4") {
                                    $__5.levelName = "钻石代理";
                                } else {
                                    $__5.levelName = "获取等级失败";
                                }
                                $__5.higher_up = obj.slice(18, 29);
                                axios({
                                    method: "post",
                                    url: ($__5.siteUrl + "/getUser"),
                                    data: {
                                        uid: $__5.higher_up
                                    }
                                }).then(function(response) {
                                    console.log(response);
                                    if (response.data.result == 200) {
                                        var data = response.data.data;
                                        $__5.higher_name = data.name;
                                    } else {
                                        alert("请求失败");
                                    }
                                }).catch(function(error) {
                                    console.log(error);
                                });
                            }
                            axios({
                                method: "post",
                                url: ($__5.siteUrl + "/getEncodeMessage"),
                                data: {
                                    higher_up: $__5.higher_up,
                                    level: $__5.level
                                }
                            }).then(function(response) {
                                if (response.data.result == 200) {
                                    $__5.encode = response.data.data;
                                } else {
                                    alert("请求失败");
                                }
                            }).catch(function(error) {
                                console.log(error);
                            });
                        }
                    } else {
                        alert(response.data.message);
                    }
                }).catch(function(error) {
                    console.log(error);
                });
            }
        });
    </script>
    <style scoped>
        .info {
            height: 51px;
            background: #fff;
            line-height: 50px;
            padding-left: 10px;
            font-size: 14px;
            border-bottom: 1px solid #f2f2f2;
            position: relative;
        }
        
        .info input {
            text-align: right;
            padding-right: 10px;
            height: 50px;
            color: #666;
            border: none;
            outline: none;
        }
        
        .fl {
            width: 45%;
        }
        
        .fr {
            width: 55%;
        }
        
        .info select {
            height: 50px;
        }
        
        .photo {
            height: 90px;
            background: #fff;
            line-height: 50px;
            padding-left: 10px;
            font-size: 14px;
            border-bottom: 1px solid #f2f2f2;
            position: relative;
        }
        
        .photo .addfile {
            width: 120px;
            height: 70px;
            background: #ddd;
            position: absolute;
            right: 0px;
            top: 0px;
            margin: 10px;
            text-align: center;
        }
        
        .photo .addfile .img {
            width: 50px;
            margin-top: 10px;
        }
        
        .photo .file {
            width: 120px;
            height: 70px;
            position: absolute;
            right: 0px;
            top: 0px;
            margin: 10px;
            z-index: 555;
            opacity: 0;
        }
        
        .btn {
            width: 100%;
        }
        
        .btn button {
            width: 80%;
            height: 40px;
            background: #5aa0c8;
            border: none;
            color: #fff;
            outline: none;
            margin-left: 10%;
            margin-top: 50px;
            margin-bottom: 50px;
            border-radius: 5px;
        }
        
        .level {
            color: red;
            line-height: 30px;
            margin-left: 10px;
        }
        
        span {
            color: red;
            line-height: 30px;
            margin-left: 10px;
        }
        
        .yzm {
            background: #5aa0c8;
            text-align: center;
            height: 40px;
            line-height: 40px;
            color: #fff;
            border-radius: 5px;
            position: absolute;
            right: 10px;
            bottom: 5px;
            width: 35%;
            font-size: 13px;
            border: none;
        }
    </style>
</body>

</html>